﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;

namespace SafeCalculations.UnitTests
{
    [TestClass]
    public class SafeStatisticsTests
    {

#if RUN_LARGE_UNIT_TESTS
        /// <summary>
        /// This test takes a long time (somewhere around 2-5 minutes). This is the only direct test for more than 2^32 values.
        /// </summary>
        [TestMethod]
        public void CalculatesCorrectAverageForMoreThanUintMaxValues()
        {
            var result = SafeStatistics.CalculateAverage(Enumerable.Range(1, int.MaxValue).Concat(Enumerable.Range(int.MinValue + 1, int.MaxValue)).Concat(Enumerable.Range(1, 100)).Concat(Enumerable.Range(-100, 100)));
            Assert.AreEqual(0, result.IntegerPart);
            Assert.AreEqual(0, result.RemainderNumerator);
        }
#endif

        [TestMethod]
        public void CalculatesCorrectAverageForSmallNumberOfValues()
        {
            int numValues = 100;
            var result = SafeStatistics.CalculateAverage(Enumerable.Range(1, numValues).Concat(Enumerable.Range(-numValues, numValues)));
            Assert.AreEqual(0, result.IntegerPart);
            Assert.AreEqual(0, result.RemainderNumerator);
        }
    }
}
